package com.shushan.home.bean;

import android.support.annotation.NonNull;

import com.android.net.bean.NetBaseBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ExerciseBean
 * @Desciption: //TODO
 * @author: yichaohua
 * @date: 2018-12-08
 */
public class ExerciseBean extends NetBaseBean implements Comparable<ExerciseBean>{

    public int id;
    public String practice_name;
    public String practice_dec;
    public int type;//1、单图模式 2、三图模式
    public int order_no;//排序
    public int state;
    private List<PracticeBean> practiceBeanList = new ArrayList<PracticeBean>();

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        id = jsonObject.optInt("id",0);
        practice_name = jsonObject.optString("practice_name","");
        practice_dec = jsonObject.optString("practice_dec","");
        type = jsonObject.optInt("type",0);
        order_no = jsonObject.optInt("order_no",0);
        state = jsonObject.optInt("state",0);

        JSONArray jsonArray = jsonObject.optJSONArray("url_json");
        if(jsonArray != null){
            for (int i = 0;i < jsonArray.length();i++){
                JSONObject object = jsonArray.optJSONObject(i);
                PracticeBean practiceBean = new PracticeBean();
                practiceBean.initByJson(object);
                practiceBeanList.add(practiceBean);
            }
        }
    }

    public List<PracticeBean> getPracticeBeanList() {
        return practiceBeanList;
    }

    public void setPracticeBeanList(List<PracticeBean> practiceBeanList) {
        this.practiceBeanList = practiceBeanList;
    }

    @Override
    public int compareTo(@NonNull ExerciseBean exerciseBean) {
        return order_no - exerciseBean.order_no;
    }
}
